// pages/home/index/index.js
const app = getApp();
const http = require('../../../utils/http.js')
Component({
  options: {
    addGlobalClass: true,
  },
  lifetimes: {
    attached: function() {
      if (app.globalData.customer) {
        this.setData({
            customer: app.globalData.customer,
            ggBannerBool:app.globalData.ggBannerBool
        })
      } else {
          app.userInfoReadyCallback = res => {
              this.setData({
                  customer: res.data,
                  ggBannerBool:app.globalData.ggBannerBool
              })
          }
      }
      this.selectAllIndex()
    }
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示
      this.setData({
        customer: app.globalData.customer
      })
      //this.selectAllIndex()
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    swiperList: null,
    gridList: null,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    ggBtn:function(){//启动图
      var that = this;
      var animation = wx.createAnimation({
        timingFunction: 'ease-in'
      });
      this.animation = animation;
      animation.opacity(0).scale(0,0).step({duration: 100});
      that.setData({
        animationData: animation.export()
      })
      setTimeout(()=>{
        this.setData({
            ggBanner: 'none'
        })
      }, 100);
      app.globalData.ggBannerBool=false
    },
    selectAllIndex() {
        //轮播和九宫格
        http.get('/api/index/selectSwiperAndGrids', {activityType: 1}).then(res => {
          if (res.code == 200) {
              if(res.data){
                  this.setData({
                    swiperList: res.data.swipers,
                    gridList: res.data.grids
                  })
              }else{
                  this.setData({
                    swiperList: res.data.swipers,
                    gridList: res.data.grids
                  })
              }
              
          }
      })
      //查询限时
      http.get('/api/index/getListByType', {activityType: 1,type:1}).then(res => {
          if (res.code == 200) {
              if(res.data){
                  this.setData({
                      xsqgItem: res.data
                  })
              }else{
                  this.setData({
                      xsqgItem: false
                  })
              }
              
          }
      })
      //普通活动
      http.get('/api/index/getListByType', {activityType: 2,type:1}).then(res => {
        if (res.code == 200) {
            if(res.data){
                this.setData({
                    tpItem: res.data
                })
            }else{
                this.setData({
                    tpItem: false
                })
            }
            
        }
      })
      //权益卡
      http.get('/api/purchase/selectEquityCard').then(res => {
        if (res.code == 200) {
            if(res.data){
                this.setData({
                  qykItem: res.data
                })
            }else{
                this.setData({
                  qykItem: false
                })
            }
            
        }
      })
    }
  }
})
